﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using LogisticsBLL;
using System.Web.SessionState;
using System.Data.SqlClient;

namespace WebLosgic.HeanderAJAX
{
    /// <summary>
    /// LoginHandler 的摘要说明
    /// </summary>
    public class LoginHandler : IHttpHandler,IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            #region
            string Act = context.Request.Form["Act"];
            string pwd = context.Request.Form["pwd"];
            SqlDataReader read = LogBLL.logs(Act, pwd);
            string msg = "";
            if (read.Read())
            {
                string Name = read["UserName"].ToString();
                int Uid = Convert.ToInt32(read["UserID"]);
                context.Session["UserIDs"] = Uid;
                context.Session["names"] = Name;
                context.Session["Act"] = read["Account"];

                string Behavor = "" + Name + ":登录系统";
                int TypeId = 1;
                int UserID = Uid;
                string Parameters = Act + "," + pwd;
                string ProcName = "p_log";
                HttpRequest request = HttpContext.Current.Request;
                string result = request.ServerVariables["HTTP_X_FORWARDED_FOR"];
                if (string.IsNullOrEmpty(result)) { result = request.ServerVariables["REMOTE_ADDR"]; }
                if (string.IsNullOrEmpty(result)) { result = request.UserHostAddress; }
                if (string.IsNullOrEmpty(result)) { result = "192.168.1.0"; }
                string IP = "192.168.01.01";

                int IsExcePion = 0;
                int a = ProcBLL.InserSys(Behavor, TypeId, UserID, Parameters, ProcName, IP, IsExcePion);


                msg = "登录成功";


            }
            else
            {
                msg = "登录失败，用户名或密码错误！";
            }
            context.Response.ContentType = "text/plain";
            context.Response.Write(msg);
            #endregion
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}